package com.slofzx.nuoda.evaluation.project.controller;

import com.slofzx.nuoda.common.controller.BaseController;
import com.slofzx.nuoda.common.enums.ServiceResult;
import com.slofzx.nuoda.common.vo.AjaxResultVO;
import com.slofzx.nuoda.common.vo.PageResultVO;
import com.slofzx.nuoda.evaluation.project.dto.BatchInfoDTO;
import com.slofzx.nuoda.evaluation.project.dto.ProjectInfoDTO;
import com.slofzx.nuoda.evaluation.project.service.BatchInfoService;
import com.slofzx.nuoda.evaluation.project.vo.BatchInfoNameVO;
import com.slofzx.nuoda.evaluation.project.vo.BatchInfoVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 评价任务基本信息表控制层
 *
 * @author nuoda
 * @menu 评价任务基本信息表
 * @since 2023-10-20 09:08:55
 */
@RestController
@RequestMapping("/batch_info")
public class BatchInfoController extends BaseController {
    /**
     * 服务对象
     */
    @Autowired
    private BatchInfoService batchInfoService;

    @GetMapping("/data")
    public AjaxResultVO<List<BatchInfoVO>> queryList(BatchInfoDTO dto) {
        List<BatchInfoVO> dataList = batchInfoService.queryList(dto);
        return PageResultVO.newSuccessResult(dataList, dto.getCount());
    }

    @GetMapping("/nameList")
    public AjaxResultVO<List<BatchInfoNameVO>> queryNameList() {
        List<BatchInfoNameVO> dataList = batchInfoService.queryNameList();
        return AjaxResultVO.newSuccessResult(dataList);
    }

    @ResponseBody
    @PostMapping(value = "/create")
    public AjaxResultVO create(@RequestBody BatchInfoDTO dto) {
        ServiceResult resultEnum = batchInfoService.create(dto);
        return AjaxResultVO.getInstance(resultEnum);
    }

    @ResponseBody
    @PostMapping(value = "/update")
    public AjaxResultVO update(@RequestBody BatchInfoDTO dto) {
        ServiceResult resultEnum = batchInfoService.update(dto);
        return AjaxResultVO.getInstance(resultEnum);
    }

    @ResponseBody
    @PostMapping(value = "/delete")
    public AjaxResultVO delete(@RequestParam String id) {
        ServiceResult resultEnum = batchInfoService.deleteById(id);
        return AjaxResultVO.getInstance(resultEnum);
    }

    @ResponseBody
    @GetMapping(value = "/info/{id}")
    public AjaxResultVO<BatchInfoVO> queryById(@PathVariable String id) {
        BatchInfoVO vo = batchInfoService.queryById(id);
        return AjaxResultVO.newSuccessResult(vo);
    }

    @ResponseBody
    @PostMapping(value = "/edit_common")
    public AjaxResultVO editCommonData(@RequestBody BatchInfoDTO dto) {
        ServiceResult resultEnum = batchInfoService.editCommonData(dto);
        return AjaxResultVO.getInstance(resultEnum);
    }

    /**
     * 导入Excel
     */
    @PostMapping("/importExcel/{fileId}/{batchId}")
    public AjaxResultVO importExcel(@PathVariable String fileId,@PathVariable String batchId) {
        ServiceResult serviceResult = batchInfoService.importExcel(fileId, batchId);
        return AjaxResultVO.getInstance(serviceResult);
    }

    @RequestMapping("/exportExcel")
    public ResponseEntity<byte[]> exportExcel(HttpServletRequest request, ProjectInfoDTO projectInfoDTO) {
        return batchInfoService.exportExcel(request ,projectInfoDTO);
    }
    @RequestMapping("/downloadMergeExcel/{batchId}/{templateId}")
    public ResponseEntity<byte[]> downloadMergeExcel(HttpServletRequest request,@PathVariable("batchId") String batchId,@PathVariable("templateId") String templateId) {
        return batchInfoService.downloadMergeExcel(request ,batchId, templateId);
    }

    @RequestMapping("/batchExportExcel/{batchId}/{templateId}")
    public ResponseEntity<byte[]> batchExportExcel(HttpServletRequest request, ProjectInfoDTO projectInfoDTO) {
        return batchInfoService.batchExportExcel(request ,projectInfoDTO);
    }

}
